/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.minierp.bean.AdjustBillBean;
import com.minierp.bean.OrderParameterCarrier;
import com.minierp.bean.QueryParameterBean;
import com.minierp.bean.QueryResult;
import com.minierp.bean.UserBean;
import com.minierp.bean.UserStatus;
import com.minierp.dao.AdjustBillDao;
import com.minierp.dao.AdjustBillItemDao;
import com.minierp.dao.BusinessBillDao;
import com.minierp.dao.CodeRuleDao;
import com.minierp.dao.DepartmentDao;
import com.minierp.dao.FinanceDetailDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.PayBillDao;
import com.minierp.dao.QueryDao;
import com.minierp.dao.ReceiveBillDao;
import com.minierp.dao.TallySetDao;
import com.minierp.err.NotAllowException;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncAdjustBillMACtrHelper;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.EncInterceptorHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.AdjustBill;
import com.minierp.model.BusinessBill;
import com.minierp.model.CooperBill;
import com.minierp.model.Department;
import com.minierp.model.Establishment;
import com.minierp.model.TallySet;
import com.minierp.service.AdjustBillService;
import com.minierp.view.AdjustBillListExcelView;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class AdjustBillMACtr extends MultiActionController {
	private String AdjustTypeSelectView;
	private String dialogSuccessView;
	private String listForExamineView;
	private String infoForExamineView;
	private String listForUnExamineView;
	private String infoForUnExamineView;
	private String itemListForBusinessBillView;
	private String itemListForCooperBillView;
	private String listForEstablishmentView;
	private String searchResultView;
	private String listForCancelView;
	private String infoForCancelView;
	private String printView;
	private AdjustBillDao adjustBillDao;
	private AdjustBillItemDao adjustBillItemDao;
	private ReceiveBillDao receiveBillDao;
	private PayBillDao payBillDao;
	private DepartmentDao departmentDao;
	private TallySetDao tallySetDao;
	private QueryDao queryDao;
	private BusinessBillDao businessBillDao;
	private FinanceDetailDao financeDetailDao;
	private CodeRuleDao codeRuleDao;
	private IdGenerator idGenerator;
	private AdjustBillService adjustBillService;
	private DataSource dataSource;

	public ModelAndView handleAdjustTypeSelect(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "ADJU_BILL")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String billType = request.getParameter("bill_type");
			ModelAndView mv = new ModelAndView(this.AdjustTypeSelectView);
			mv.addObject("billType", billType);
			return mv;
		}
	}

	public String getAdjustTypeSelectView() {
		return this.AdjustTypeSelectView;
	}

	public void setAdjustTypeSelectView(String adjustTypeSelectView) {
		this.AdjustTypeSelectView = adjustTypeSelectView;
	}

	public ModelAndView handleExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String idStr = request.getParameter("id_str");
		String flag = request.getParameter("flag");
		boolean examined = false;
		if (flag != null && flag.equals("1")) {
			examined = true;
		}

		String[] arr = idStr.split(";");
		boolean num = false;
		String msg;
		byte arg18;
		if (!examined) {
			if (!EncCommonHelper.checkPrivilege(request, "ADJU_UN_EXAM")) {
				throw new Exception("Permission deny!");
			}

			try {
				for (int examinerId = 0; examinerId < arr.length; ++examinerId) {
					this.adjustBillService.txUnExamine(
							Long.parseLong(arr[examinerId]),
							this.adjustBillDao, this.adjustBillItemDao,
							this.receiveBillDao, this.payBillDao,
							this.businessBillDao, this.idGenerator,
							this.financeDetailDao);
				}

				msg = "反审核成功";
			} catch (NotAllowException arg16) {
				msg = arg16.getMessage();
			} catch (CannotAcquireLockException arg17) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg18 = 1;
		} else {
			if (!EncCommonHelper.checkPrivilege(request, "ADJU_EXAM")) {
				throw new Exception("Permission deny!");
			}

			long arg19 = ub.getStaffer().getId();
			String examinerName = ub.getStaffer().getStafferName();

			try {
				for (int w = 0; w < arr.length; ++w) {
					this.adjustBillService.txExamine(Long.parseLong(arr[w]),
							this.adjustBillDao, this.adjustBillItemDao,
							this.receiveBillDao, this.payBillDao,
							this.businessBillDao, this.idGenerator, arg19,
							examinerName);
				}

				msg = "审核成功";
			} catch (NotAllowException arg14) {
				msg = arg14.getMessage();
			} catch (CannotAcquireLockException arg15) {
				msg = "事务冲突故障，请重新操作！";
			}

			arg18 = 1;
		}

		mv.addObject("returnValue", String.valueOf(arg18));
		EncCommonHelper.setAlertMessage(request, msg);
		return mv;
	}

	public ModelAndView handleListForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "ADJU_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.adjustBillDao.getListForExamineCount(searchKey,
					false, Long.parseLong(tsId), ub, managerId, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.adjustBillDao.getListForExamine(searchKey, false,
					Long.parseLong(tsId), ub, managerId, allowStart,
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForExamineView);
		String id = request.getParameter("id");
		mv.addObject("record", this.getAdjustBill(Long.parseLong(id)));
		return mv;
	}

	public ModelAndView handleListForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "ADJU_UN_EXAM")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForUnExamineView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.adjustBillDao.getListForExamineCount(searchKey,
					true, Long.parseLong(tsId), ub, managerId, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.adjustBillDao.getListForExamine(searchKey, true,
					Long.parseLong(tsId), ub, managerId, allowStart,
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForUnExamine(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForUnExamineView);
		String id = request.getParameter("id");
		mv.addObject("record", this.getAdjustBill(Long.parseLong(id)));
		return mv;
	}

	public ModelAndView handleListForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "ADJU_CANC")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listForCancelView);
			String searchKey = request.getParameter("search_key");
			String tsId = request.getParameter("ts_id");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			List tsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			long managerId = 0L;
			if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}

			Date allowStart = null;
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				allowStart = EncCommonHelper.getEarlDataDate(request);
			}

			int perPageNum = EncCommonHelper.getPageSize(request);
			int total = this.adjustBillDao.getListForCancelCount(searchKey,
					Long.parseLong(tsId), ub, managerId, allowStart);
			int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
					perPageNum);
			int startIndex = (pageno - 1) * perPageNum;
			List list = this.adjustBillDao.getListForCancel(searchKey,
					Long.parseLong(tsId), ub, "", managerId, allowStart,
					startIndex, perPageNum);
			mv.addObject("qr", EncCommonHelper.parseQueryResult(list, total,
					perPageNum, pageno));
			mv.addObject("searchKey", searchKey);
			mv.addObject("tsId", tsId);
			mv.addObject("tsList", tsList);
			return mv;
		}
	}

	public ModelAndView handleInfoForCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.infoForCancelView);
		String id = request.getParameter("id");
		mv.addObject("record", this.getAdjustBill(Long.parseLong(id)));
		return mv;
	}

	public ModelAndView handleCancel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.dialogSuccessView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (!EncCommonHelper.checkPrivilege(request, "ADJU_CANC")) {
			throw new Exception("Permission deny!");
		} else {
			String id = request.getParameter("id");
			String reason = request.getParameter("reason");
			String msg = "作废成功";

			try {
				this.adjustBillService.txCancel(Long.parseLong(id), reason,
						this.adjustBillDao, this.adjustBillItemDao,
						this.receiveBillDao, this.payBillDao,
						this.businessBillDao, this.idGenerator, ub,
						this.financeDetailDao);
			} catch (NotAllowException arg8) {
				msg = arg8.getMessage();
			} catch (CannotAcquireLockException arg9) {
				msg = "事务冲突故障，请重新操作！";
			}

			mv.addObject("returnValue", id);
			EncCommonHelper.setAlertMessage(request, msg);
			return mv;
		}
	}

	private AdjustBillBean getAdjustBill(long id) throws Exception {
		AdjustBill adjustBill = (AdjustBill) this.adjustBillDao.get(
				AdjustBill.class, id);
		AdjustBillBean form = new AdjustBillBean();
		if (adjustBill != null && !adjustBill.getEnabled().equals("N")) {
			form.setAdjustBill(adjustBill);
			List itemList = this.adjustBillItemDao
					.getListByAdjustBill(adjustBill.getId());
			form.setItems(itemList);
			if (adjustBill != null) {
				Establishment est = (Establishment) this.adjustBillDao.get(
						Establishment.class, adjustBill.getClientId());
				if (est != null) {
					form.setClientName(est.getEstName());
				}

				if (adjustBill.getDepartmentId() != 0L) {
					Department d = (Department) this.adjustBillDao.get(
							Department.class, adjustBill.getDepartmentId());
					if (d != null) {
						form.setDepartmentName(d.getDepartmentName());
					}
				}

				if (adjustBill.getTallySetId() != 0L) {
					TallySet d1 = (TallySet) this.adjustBillDao.get(
							TallySet.class, adjustBill.getTallySetId());
					if (d1 != null) {
						form.setTallySetName(d1.getTitle());
					}
				}
			}

			return form;
		} else {
			throw new Exception("Record not found or enabled for id:" + id);
		}
	}

	public ModelAndView handleSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "ADJU_BILL_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.searchResultView);
			String contentType = request.getParameter("content_type");
			QueryParameterBean b = EncAdjustBillMACtrHelper.handleSearchResult(
					request, this.dataSource);
			QueryResult qr;
			if (contentType != null && contentType.equals("EXCEL")) {
				qr = this.queryDao.doQuery(b.getQParas(), b.getOParas(),
						(String[]) null, b.getShortNameMap(), b.getRetObjs(),
						(String[]) null);
			} else {
				qr = this.queryDao.doQuery(b.getCurrentPage(), b.getPageSize(),
						b.getQParas(), b.getOParas(), (String[]) null,
						b.getShortNameMap(), b.getRetObjs(), (String[]) null);
			}

			String[] retObjs = new String[]{"b.adjustType", "sum(b.cost)"};
			String[] groupObjs = new String[]{"b.adjustType"};
			List costList = this.queryDao.doQuery(b.getQParas(),
					(OrderParameterCarrier[]) null, groupObjs,
					b.getShortNameMap(), retObjs, (String[]) null).getList();
			String colAddTotal = "0";
			String colAbateTotal = "0";
			String payAddTotal = "0";
			String payAbateTotal = "0";
			String purBackAddTotal = "0";
			String purBackAbateTotal = "0";
			String cooAddTotal = "0";
			String cooAbateTotal = "0";
			if (costList != null) {
				for (int adjustTotal = 0; adjustTotal < costList.size(); ++adjustTotal) {
					Object[] ub = (Object[]) costList.get(adjustTotal);
					if (ub[0].toString().equals("COLLECT_ADD")) {
						colAddTotal = ub[1].toString();
					} else if (ub[0].toString().equals("COLLECT_ABATE")) {
						colAbateTotal = ub[1].toString();
					} else if (ub[0].toString().equals("PAY_ADD")) {
						payAddTotal = ub[1].toString();
					} else if (ub[0].toString().equals("PAY_ABATE")) {
						payAbateTotal = ub[1].toString();
					} else if (ub[0].toString().equals("PUR_BACK_ADD")) {
						purBackAddTotal = ub[1].toString();
					} else if (ub[0].toString().equals("PUR_BACK_ABATE")) {
						purBackAbateTotal = ub[1].toString();
					} else if (ub[0].toString().equals("COO_ADD")) {
						cooAddTotal = ub[1].toString();
					} else if (ub[0].toString().equals("COO_ABATE")) {
						cooAbateTotal = ub[1].toString();
					}
				}
			}

			BigDecimal arg20 = (new BigDecimal(colAddTotal))
					.subtract(new BigDecimal(colAbateTotal));
			arg20 = arg20.subtract(new BigDecimal(payAddTotal));
			arg20 = arg20.add(new BigDecimal(payAbateTotal));
			arg20 = arg20.add(new BigDecimal(purBackAddTotal));
			arg20 = arg20.subtract(new BigDecimal(purBackAbateTotal));
			arg20 = arg20.subtract(new BigDecimal(cooAddTotal));
			arg20 = arg20.add(new BigDecimal(cooAbateTotal));
			if (contentType != null && contentType.equals("EXCEL")) {
				HashMap arg22 = new HashMap();
				arg22.put("list", qr.getList());
				arg22.put("colAddTotal", colAddTotal);
				arg22.put("colAbateTotal", colAbateTotal);
				arg22.put("payAddTotal", payAddTotal);
				arg22.put("payAbateTotal", payAbateTotal);
				arg22.put("purBackAddTotal", purBackAddTotal);
				arg22.put("purBackAbateTotal", purBackAbateTotal);
				arg22.put("cooAddTotal", cooAddTotal);
				arg22.put("cooAbateTotal", cooAbateTotal);
				arg22.put("adjustTotal", arg20.toString());
				AdjustBillListExcelView v = new AdjustBillListExcelView();
				return new ModelAndView(v, arg22);
			} else {
				mv.addAllObjects(b.getParameters());
				mv.addObject("qr", qr);
				mv.addObject("colAddTotal", colAddTotal);
				mv.addObject("colAbateTotal", colAbateTotal);
				mv.addObject("payAddTotal", payAddTotal);
				mv.addObject("payAbateTotal", payAbateTotal);
				mv.addObject("purBackAddTotal", purBackAddTotal);
				mv.addObject("purBackAbateTotal", purBackAbateTotal);
				mv.addObject("cooAddTotal", cooAddTotal);
				mv.addObject("cooAbateTotal", cooAbateTotal);
				mv.addObject("adjustTotal", arg20.toString());
				mv.addObject("departmentList", this.departmentDao.getList(true));
				UserBean arg21 = EncCommonHelper.getCurrentUserAccount(request);
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, arg21));
				return mv;
			}
		}
	}

	public ModelAndView handleItemListForBusinessBill(
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView(this.itemListForBusinessBillView);
		String id = request.getParameter("id");
		String examined = request.getParameter("examined");
		boolean justExamined = false;
		if (examined != null && examined.equals("Y")) {
			justExamined = true;
		}

		BusinessBill businessBill = (BusinessBill) this.adjustBillDao.get(
				BusinessBill.class, Long.parseLong(id));
		mv.addObject("businessBill", businessBill);
		List items = this.adjustBillItemDao.getList("BUSINESS_BILL",
				Long.parseLong(id), justExamined);
		mv.addObject("items", items);
		mv.addObject("examined", examined);
		return mv;
	}

	public ModelAndView handleItemListForCooperBill(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.itemListForCooperBillView);
		String id = request.getParameter("id");
		CooperBill cooperBill = (CooperBill) this.adjustBillDao.get(
				CooperBill.class, Long.parseLong(id));
		mv.addObject("cooperBill", cooperBill);
		List items = this.adjustBillItemDao.getList("COOPER_BILL",
				Long.parseLong(id), false);
		mv.addObject("items", items);
		return mv;
	}

	public ModelAndView handleListForEstablishment(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForEstablishmentView);
		QueryParameterBean b = EncAdjustBillMACtrHelper
				.handleListForEstablishment(request, this.dataSource);
		QueryResult qr = this.queryDao.doQuery(b.getCurrentPage(),
				b.getPageSize(), b.getQParas(), b.getOParas(), (String[]) null,
				b.getShortNameMap(), b.getRetObjs(), (String[]) null);
		mv.addObject("qr", qr);
		String id = request.getParameter("id");
		mv.addObject("id", id);
		mv.addObject("est",
				this.adjustBillDao.get(Establishment.class, Long.parseLong(id)));
		return mv;
	}

	public ModelAndView handlePrint(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.printView);
		String id = request.getParameter("id");
		mv.addObject("record", this.getAdjustBill(Long.parseLong(id)));
		mv.addObject("codeRule", this.codeRuleDao.get("ADJUST_BILL"));
		mv.addObject("retVal", request.getParameter("ret_val"));
		return mv;
	}

	public ModelAndView handleAppListForExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "ADJU_EXAM")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("sk");
				json = request.getParameter("ts_id");
				String out = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long mngId = 0L;
				long tsId = 0L;
				if (json != null && !json.equals("")) {
					tsId = Long.parseLong(json);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mngId = ub.getStaffer().getId();
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				BigDecimal cost = new BigDecimal(0);
				List list = this.adjustBillDao.getAppListForExamCost(mapper,
						tsId, ub, allowStart, mngId);

				int total;
				for (total = 0; total < list.size(); ++total) {
					Object[] perPageNum = (Object[]) list.get(total);
					if (perPageNum[0] != null) {
						String pageno = (String) perPageNum[0];
						if (!pageno.equals("COLLECT_ADD")
								&& !pageno.equals("COO_ABATE")
								&& !pageno.equals("PAY_ABATE")
								&& !pageno.equals("PUR_BACK_ADD")) {
							cost = cost.subtract((BigDecimal) perPageNum[1]);
						} else {
							cost = cost.add((BigDecimal) perPageNum[1]);
						}
					}
				}

				map.put("cost", cost);
				total = this.adjustBillDao.getAppListForExamCount(mapper, tsId,
						ub, allowStart, mngId);
				int arg31 = EncCommonHelper.getPageSize(request);
				int arg32 = EncCommonHelper.getCurrentPageIndex(request, total,
						arg31);
				if (total > arg32 * arg31) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				map.put("total", Integer.valueOf(total));
				if (out != null && out.equals("Y")) {
					list = this.adjustBillDao.getAppListForExam(mapper, tsId,
							ub, allowStart, mngId, 0, arg32 * arg31);
				} else {
					list = this.adjustBillDao.getAppListForExam(mapper, tsId,
							ub, allowStart, mngId, (arg32 - 1) * arg31, arg31);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					Object[] tsItems = (Object[]) list.get(tmpList);
					AdjustBill i = (AdjustBill) tsItems[0];
					String item = (String) tsItems[1];
					String ts = "";
					if (i.getCreateTime() != null) {
						ts = sfl.format(i.getCreateTime());
					}

					HashMap item1 = new HashMap();
					item1.put("cost", i.getCost());
					item1.put("creaName", i.getCreaterName());
					item1.put("creaTime", ts);
					item1.put("estName", item);
					item1.put("id", Long.valueOf(i.getId()));
					item1.put("date", sf.format(i.getAdjustDate()));
					item1.put("type", i.getAdjustType());
					items.add(item1);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg33 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg34 = new ArrayList();

					for (int arg35 = 0; arg35 < arg33.size(); ++arg35) {
						HashMap arg36 = new HashMap();
						TallySet arg37 = (TallySet) arg33.get(arg35);
						arg36.put("id", Long.valueOf(arg37.getId()));
						arg36.put("name", arg37.getTitle());
						arg34.add(arg36);
					}

					map.put("tsItems", arg34);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg28) {
				map.put("status", "ERROR");
				map.put("errMsg", arg28.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg29 = new ObjectMapper();
		json = arg29.writeValueAsString(map);
		ServletOutputStream arg30 = response.getOutputStream();
		arg30.write(json.getBytes("utf-8"));
		arg30.flush();
		arg30.close();
		return null;
	}

	public ModelAndView handleAppListForUnExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "ADJU_UN_EXAM")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("sk");
				json = request.getParameter("ts_id");
				String out = request.getParameter("show_prev");
				String initQuer = request.getParameter("init_quer");
				long mngId = 0L;
				long tsId = 0L;
				if (json != null && !json.equals("")) {
					tsId = Long.parseLong(json);
				}

				if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
					mngId = ub.getStaffer().getId();
				}

				Date allowStart = null;
				if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
					allowStart = EncCommonHelper.getEarlDataDate(request);
				}

				int total = this.adjustBillDao.getAppListForUnExamCount(mapper,
						tsId, ub, allowStart, mngId);
				int perPageNum = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, perPageNum);
				if (total > pageno * perPageNum) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				List list;
				if (out != null && out.equals("Y")) {
					list = this.adjustBillDao.getAppListForUnExam(mapper, tsId,
							ub, allowStart, mngId, 0, pageno * perPageNum);
				} else {
					list = this.adjustBillDao.getAppListForUnExam(mapper, tsId,
							ub, allowStart, mngId, (pageno - 1) * perPageNum,
							perPageNum);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < list.size(); ++tmpList) {
					Object[] tsItems = (Object[]) list.get(tmpList);
					AdjustBill i = (AdjustBill) tsItems[0];
					String item = (String) tsItems[1];
					String ts = "";
					if (i.getExamineTime() != null) {
						ts = sfl.format(i.getExamineTime());
					}

					HashMap item1 = new HashMap();
					item1.put("cost", i.getCost());
					item1.put("examName", i.getExaminerName());
					item1.put("examTime", ts);
					item1.put("estName", item);
					item1.put("id", Long.valueOf(i.getId()));
					item1.put("date", sf.format(i.getAdjustDate()));
					item1.put("type", i.getAdjustType());
					items.add(item1);
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg30 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg31 = new ArrayList();

					for (int arg32 = 0; arg32 < arg30.size(); ++arg32) {
						HashMap arg33 = new HashMap();
						TallySet arg34 = (TallySet) arg30.get(arg32);
						arg33.put("id", Long.valueOf(arg34.getId()));
						arg33.put("name", arg34.getTitle());
						arg31.add(arg33);
					}

					map.put("tsItems", arg31);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg27) {
				map.put("status", "ERROR");
				map.put("errMsg", arg27.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg28 = new ObjectMapper();
		json = arg28.writeValueAsString(map);
		ServletOutputStream arg29 = response.getOutputStream();
		arg29.write(json.getBytes("utf-8"));
		arg29.flush();
		arg29.close();
		return null;
	}

	public ModelAndView handleAppInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();

		try {
			long mapper = Long.parseLong(request.getParameter("id"));
			AdjustBill out = (AdjustBill) this.adjustBillDao.get(
					AdjustBill.class, mapper);
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			String depName = "";
			String estName = "";
			String tsName = "";
			String creaTime = "";
			if (out.getDepartmentId() != 0L) {
				Department est = (Department) this.adjustBillDao.get(
						Department.class, out.getDepartmentId());
				if (est != null) {
					depName = est.getDepartmentName();
				}
			}

			Establishment est1 = (Establishment) this.adjustBillDao.get(
					Establishment.class, out.getClientId());
			if (est1 != null) {
				estName = est1.getEstName();
			}

			TallySet ts = (TallySet) this.adjustBillDao.get(TallySet.class,
					out.getTallySetId());
			if (ts != null) {
				tsName = ts.getTitle();
			}

			if (out.getCreateTime() != null) {
				creaTime = sfl.format(out.getCreateTime());
			}

			map.put("estName", estName);
			map.put("code", out.getBillCode());
			map.put("date", sf.format(out.getAdjustDate()));
			map.put("desc", PageHelper.parseNull(out.getDescription()));
			map.put("cost", out.getCost());
			map.put("type", out.getAdjustType());
			map.put("mngName", out.getManagerName());
			map.put("depName", depName);
			map.put("mark", PageHelper.parseNull(out.getMark()));
			map.put("creaName", out.getCreaterName());
			map.put("creaTime", creaTime);
			String examName = "";
			String examTime = "";
			if (out.getExamined().equals("Y")) {
				examName = out.getExaminerName();
				if (out.getExamineTime() != null) {
					examTime = sfl.format(out.getExamineTime());
				}
			}

			map.put("exam", out.getExamined());
			map.put("examName", examName);
			map.put("examTime", examTime);
			map.put("tsName", tsName);
			map.put("status", "OK");
			map.put("errMsg", "");
		} catch (Exception arg16) {
			map.put("status", "ERROR");
			map.put("errMsg", arg16.toString());
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		String json = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleAppExam(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String status = "";
		String errMsg = "";
		if (ub == null) {
			status = "NO_LOGIN";
		} else {
			String map = request.getParameter("type");
			String mapper = request.getParameter("id");
			if (map != null && map.equals("UNEXAM")) {
				if (!EncCommonHelper.checkPrivilege(request, "ADJU_UN_EXAM")) {
					status = "ERROR";
					errMsg = "您还没有此功能的使用权限，请确认返回！";
				} else {
					try {
						this.adjustBillService.txUnExamine(
								Long.parseLong(mapper), this.adjustBillDao,
								this.adjustBillItemDao, this.receiveBillDao,
								this.payBillDao, this.businessBillDao,
								this.idGenerator, this.financeDetailDao);
						status = "OK";
					} catch (CannotAcquireLockException arg14) {
						status = "ERROR";
						errMsg = "事务冲突故障，请重新操作！";
					} catch (NotAllowException arg15) {
						status = "ERROR";
						errMsg = arg15.getMessage();
					}
				}
			} else if (!EncCommonHelper.checkPrivilege(request, "ADJU_EXAM")) {
				status = "ERROR";
				errMsg = "您还没有此功能的使用权限，请确认返回！";
			} else {
				long json = ub.getStaffer().getId();
				String examinerName = ub.getStaffer().getStafferName();

				try {
					this.adjustBillService.txExamine(Long.parseLong(mapper),
							this.adjustBillDao, this.adjustBillItemDao,
							this.receiveBillDao, this.payBillDao,
							this.businessBillDao, this.idGenerator, json,
							examinerName);
					status = "OK";
				} catch (NotAllowException arg12) {
					status = "ERROR";
					errMsg = arg12.getMessage();
				} catch (CannotAcquireLockException arg13) {
					status = "ERROR";
					errMsg = "事务冲突故障，请重新操作！";
				}
			}
		}

		HashMap map1 = new HashMap();
		map1.put("status", status);
		map1.put("errMsg", errMsg);
		ObjectMapper mapper1 = new ObjectMapper();
		String json1 = mapper1.writeValueAsString(map1);
		ServletOutputStream out = response.getOutputStream();
		out.write(json1.getBytes("utf-8"));
		out.flush();
		out.close();
		return null;
	}

	public AdjustBillDao getAdjustBillDao() {
		return this.adjustBillDao;
	}

	public void setAdjustBillDao(AdjustBillDao adjustBillDao) {
		this.adjustBillDao = adjustBillDao;
	}

	public String getDialogSuccessView() {
		return this.dialogSuccessView;
	}

	public void setDialogSuccessView(String dialogSuccessView) {
		this.dialogSuccessView = dialogSuccessView;
	}

	public AdjustBillItemDao getAdjustBillItemDao() {
		return this.adjustBillItemDao;
	}

	public void setAdjustBillItemDao(AdjustBillItemDao adjustBillItemDao) {
		this.adjustBillItemDao = adjustBillItemDao;
	}

	public String getInfoForExamineView() {
		return this.infoForExamineView;
	}

	public void setInfoForExamineView(String infoForExamineView) {
		this.infoForExamineView = infoForExamineView;
	}

	public String getInfoForUnExamineView() {
		return this.infoForUnExamineView;
	}

	public void setInfoForUnExamineView(String infoForUnExamineView) {
		this.infoForUnExamineView = infoForUnExamineView;
	}

	public String getListForExamineView() {
		return this.listForExamineView;
	}

	public void setListForExamineView(String listForExamineView) {
		this.listForExamineView = listForExamineView;
	}

	public String getListForUnExamineView() {
		return this.listForUnExamineView;
	}

	public void setListForUnExamineView(String listForUnExamineView) {
		this.listForUnExamineView = listForUnExamineView;
	}

	public DepartmentDao getDepartmentDao() {
		return this.departmentDao;
	}

	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	public QueryDao getQueryDao() {
		return this.queryDao;
	}

	public void setQueryDao(QueryDao queryDao) {
		this.queryDao = queryDao;
	}

	public String getSearchResultView() {
		return this.searchResultView;
	}

	public void setSearchResultView(String searchResultView) {
		this.searchResultView = searchResultView;
	}

	public String getItemListForBusinessBillView() {
		return this.itemListForBusinessBillView;
	}

	public void setItemListForBusinessBillView(
			String itemListForBusinessBillView) {
		this.itemListForBusinessBillView = itemListForBusinessBillView;
	}

	public String getListForEstablishmentView() {
		return this.listForEstablishmentView;
	}

	public void setListForEstablishmentView(String listForEstablishmentView) {
		this.listForEstablishmentView = listForEstablishmentView;
	}

	public String getInfoForCancelView() {
		return this.infoForCancelView;
	}

	public void setInfoForCancelView(String infoForCancelView) {
		this.infoForCancelView = infoForCancelView;
	}

	public String getListForCancelView() {
		return this.listForCancelView;
	}

	public void setListForCancelView(String listForCancelView) {
		this.listForCancelView = listForCancelView;
	}

	public ReceiveBillDao getReceiveBillDao() {
		return this.receiveBillDao;
	}

	public void setReceiveBillDao(ReceiveBillDao receiveBillDao) {
		this.receiveBillDao = receiveBillDao;
	}

	public AdjustBillService getAdjustBillService() {
		return this.adjustBillService;
	}

	public void setAdjustBillService(AdjustBillService adjustBillService) {
		this.adjustBillService = adjustBillService;
	}

	public DataSource getDataSource() {
		return this.dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public PayBillDao getPayBillDao() {
		return this.payBillDao;
	}

	public void setPayBillDao(PayBillDao payBillDao) {
		this.payBillDao = payBillDao;
	}

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public String getItemListForCooperBillView() {
		return this.itemListForCooperBillView;
	}

	public void setItemListForCooperBillView(String itemListForCooperBillView) {
		this.itemListForCooperBillView = itemListForCooperBillView;
	}

	public String getPrintView() {
		return this.printView;
	}

	public void setPrintView(String printView) {
		this.printView = printView;
	}

	public BusinessBillDao getBusinessBillDao() {
		return this.businessBillDao;
	}

	public void setBusinessBillDao(BusinessBillDao businessBillDao) {
		this.businessBillDao = businessBillDao;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}

	public FinanceDetailDao getFinanceDetailDao() {
		return this.financeDetailDao;
	}

	public void setFinanceDetailDao(FinanceDetailDao financeDetailDao) {
		this.financeDetailDao = financeDetailDao;
	}
}